Part Number Hot Search : 
P0720SB D74ALV 01000 DM064 P2013DP Z82D5 ZTX504 00500
Product Description
Full Text Search
 

To Download AN969 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  AN969/0102 1/10 AN969 application note sci communication between st7 and pc by microcontroller division applications introduction this document presents a standard communications interface between a st7 microcontroller and a pc. this communication is done through the st7 sci peripheral and a serial port of the pc using the rs232 protocol. 1
2/10 sci communication between st7 and pc 1 sci communication the main features of the sci communication peripheral are summarized below. refer to your st7 datasheet for more details. 1.1 main features the serial communication interface (sci) offers a flexible means of full-duplex data exchange with external equipment requiring an industry standard nrz asynchronous serial data format. the sci allows a very wide range of baud rates with different baud rates for transmission and reception. for sci communication, only two signals are needed, one for transmission and the other for reception. no clock signal is needed as it works in asynchronous mode. each device has a transmit data output pin (tdo pin) and a receive data input pin (rdi pin). see figure 1. figure 1. st7 and sci interface set-up the user must be very careful in identifying the use of each pin. this can easily be done putting the device in transmission and checking with an oscilloscope if a transmission frame is present or not. 1.2 baud rates transmission and reception can be driven by their own baud rate generator. however be aware that to communicate correctly, the receiver must have a reception baud rate strictly equal to the transmission baud rate of the transmitter. if not, the communication will be cor- rupted . as long as this condition is met, a wide range of baud rates is possible. st7 sci interface device tdo rdi rdi tdo 2
3/10 sci communication between st7 and pc 1.3 frames any transmission is least significant bit first. a data word can be 8 or 9 bits long. a data frame begins with a ?start bit?, which is a 0 bit and ends with a ?stop bit?, which is a 1 bit. see figure 2. two special frames are also managed : an idle character is interpreted as an entire frame of 1 bits followed by the start bit of the next frame which contains data. a break character is detected when receiving 0 bits for some multiple of the frame period. at the end of the last break, the transmitter inserts an extra 1 bit to acknowledge the next start bit. figure 2. frames and word length bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8 start bit stop bit next start bit idle frame bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 start bit stop bit next start bit start bit idle frame start bit 9-bit word length (m bit of scicr1 is set) 8-bit word length (m bit of scicr1 is reset) break frame start bit extra 1 data frame break frame start bit extra 1 data frame next data frame next data frame
4/10 sci communication between st7 and pc 2 rs232 communication with a pc 2.1 main features the electrical and protocol characteristics of rs232 are different from those of the st7 sci peripheral. in rs232 communication, high level is typically +7v and low level is typically -7v, while the sci peripheral works with ttl levels (0, +5v). furthermore, the polarities are different. a 1 bit coming from the sci corresponds to a 0 bit in rs232, and a 0 bit to a 1 bit. it is true for all bits including the start and stop bit . so it is necessary to implement a conversion between the pc and the sci peripheral. in this application a max232 is used for this purpose. 2.2 pc configuration the pc will be used as a terminal. the description below refers to the windows 98 environ- ment. this terminal application is called hyperterminal. under windows, open the ?hyperterminal? application. to configure it, go to the communica- tion parameters menu. the options of this window must be the same as the ones defined with your st7. after selecting the right serial communication port, select the same baud rate as the one con- figured in the micro. as the pc accepts only one baud rate, transmission and reception baud rates will have the same value. data word length will be 8 bits, but you can choose to use 1 or 2 stop bits. ?flow control? can be either xon/xoff or none (the st72f264.ht file is also pro- vided in the corresponding zip file). the pc is then correctly configured.
5/10 sci communication between st7 and pc 3 st72f264 configuration this application was implemented with a st72f264. this microcontroller uses a 16 mhz ex- ternal clock (quartz). a description of the baud rate selection is given later in this application note. 3.1 general initialization the st72f264 internal clock (f cpu ) works at 16mhz/2 = 8mhz. two pins of the st7 are used : - the tdo pin (transmit data output, alternate function of pa7). - the rdi pin (receive data input, alternate function of pa5). the pa7, pa5 pins must be initialized as floating inputs (please refer to the datasheet), the value of the port a data register does not matter. 3.2 sci configuration the peripheral is configured using the 2 sci control registers (scicr1, scicr2), and the baud rate register (brr) or the 2 extended baud rate registers of the st72f264 (etpr, erpr). as in this application a polling strategy is used, sci interruptions are disabled (tie, tcie, rie, ilie bits of scicr2 register are reset). 3.2.1 resetting control registers first, the reset status is forced to the control registers and pending interrupts are cleared. 3.2.2 baud rates selection then the baud rates must be selected. we should always have the same baud rates in the pc and in the sci. in this application, the extended transmit prescaler division register (etpr) and the ex- tended receive prescaler division register (erpr) are not used and so are in reset state. therefore the baud rates are calculated as follows: tx = f cpu /(16*pr*tr) rx = f cpu /(16*pr*rr) where pr = 1, 3, 4 or 13 (scp0 and scp1 bits in the brr register), tr = 1, 2, 4, 8, 16, 32, 64 or 128 (sct0, sct1 and sct2 bits of the bbr register) and rr = 1, 2, 4, 8, 16, 32, 64 or 128 (scr0, scr1 and scr2 bits of the brr register). for example, in our application, if we want 9600 as baud rate, we have to choose pr = 13 and tr = rr = 4.
6/10 sci communication between st7 and pc note : etpr and erpr can be used to finetune the baud rate. when etpr and erpr con- tain any value other than 0, the brr register is disabled and the baud rates are given by the formula: tx = f cpu /(16*eptr*pr*tr) rx = f cpu /(16*erpr*pr*rr) where eptr and erpr = 1 to 255. 3.2.3 word length the word length is selected by the m bit in the scicr1 register. in the application, data length is always 8 bits, but the user can force a second stop bit. this is done using a 9-bit word length and setting the 9 th bit (t8 bit of scicr1). when receiving data, r8 bit will always be set (reception of 2 stop bits). special bits (pce,ps,pie) are also available to use the sci with parity (not used in this appli- cation). refer to the datasheet for more information. 3.2.4 selecting reception and transmission modes the selection is made using the scicr2 register. transmission is enabled or disabled depending on the value of the te bit of scicr2 (te = 1, transmission enabled). when disabled, the tdo pin is free for general purpose i/o. reception is enabled or disabled depending on the value of the re bit of scicr2 (re = 1, re- ception enabled). when disabled, the rdi pin is is free for general purpose i/o. when reception is disabled, no data must be sent to the st7. if data are to be received at this time, the re bit must be set. otherwise a wrong byte might be detected when going back into reception mode. 70 r8 t8 scid m wake pce ps pie 70 tie tcie rie ilie te re rwu sbk
7/10 sci communication between st7 and pc 4 sci communication between st7 and pc via rs232 the software for this application is the sci driver. the complete software can be found in the the st internet website. it is of course only an example. it is up to the user to adapt it to his specific application. 4.1 general description in this application, a st72f264 is connected to a pc. the communication is performed using the ?hyperterminal? application of windows 98. characters are sent by the pc in ascii code to the st7. every 4 characters received by the st7 are sent back to the pc and can be read on its screen. the software is a polling sci communication between an st72f264 and a pc via rs232. the communication works at 9600bps and has 1 stop bit. the first part of the program performs the initialization of the st72f264, core and sci periph- eral. then it enters transmission mode, sends the content of a 4-byte buffer to the pc. the initial- ized value of the buffer is ?test? in ascii code. when the 4 characters are sent, transmission mode is ended and the sci peripheral enters reception mode. in reception mode, the software waits for the user to send 4 ascii characters from the pc. each character is put in the buffer until the fourth is received. then reception mode is ended, and goes back to transmission mode which will send the new contents of the buffer and so on. as the st7 sends the same characters as received, it is very easy to check if the communica- tion is correct. note that this program does not manage communication errors. 4.2 hardware the st7 sci peripheral cannot be directly connected to a pc, as it uses the rs232 protocol. the conversion between sci and rs232 can be done using a max232. an overview sche- matic is presented below (figure 3.).
8/10 sci communication between st7 and pc figure 3. overview schematic be sure that the three main devices (pc, st7, max232) have the same electrical reference (gnd). the receive data pin (rd) of the serial port of the pc must correspond to the tdo pin of the st7, and the transmit data pin (td) to the rdi pin. 4.3 flowcharts the flowcharts of the application are presented below (figure 4., figure 5.). figure 4. initialization pc terminal serial port td rd tdo rdi ground max232 in out out in st72f264 gnd gnd gnd start st72311 initialization default value of buffer sci peripheral initialization a
9/10 sci communication between st7 and pc figure 5. transmission mode, reception mode 4.4 software all the source files in assembly code are given in the zip file with application note. the source files are for guidance only. stmicroelectronics shall not be held liable for any di- rect, indirect or consequential damages with respect to any claims arising from use of this soft- ware. a nb = 4 set sci peripheral in transmission mode send the byte from address (nb-1) of buffer nb = nb - 1 byte sent ? nb = 0 ? b no yes no yes b nb = 4 set sci peripheral in reception mode put new byte into buffer at address (nb-1) nb = nb - 1 new byte nb = 0 ? a no yes no yes received ?
10/10 sci communication between st7 and pc the present note which is for guidance only aims at providing customers with information regarding their products in order for them to save time. as a result, stmicroelectronics shall not be held liable for any direct, indirect or consequential damages with respect to any claims arising from the content of such a note and/or the use made by customers of the information contained herein in connexion with their products. information furnished is believed to be accurate and reliable. however, stmicroelectronics assumes no responsibility for the co nsequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. no license is granted by implication or otherwise under any patent or patent rights of stmicroelectronics. specifications mentioned in this publicati on are subject to change without notice. this publication supersedes and replaces all information previously supplied. stmicroelectronics prod ucts are not authorized for use as critical components in life support devices or systems without the express written approval of stmicroele ctronics. the st logo is a registered trademark of stmicroelectronics ? 2002 stmicroelectronics - all rights reserved. purchase of i 2 c components by stmicroelectronics conveys a license under the philips i 2 c patent. rights to use these components in an i 2 c system is granted provided that the system conforms to the i 2 c standard specification as defined by philips. stmicroelectronics group of companies australia - brazil - canada - china - finland - france - germany - hong kong - india - israel - italy - japan malaysia - malta - morocco - singapore - spain - sweden - switzerland - united kingdom - u.s.a. http://www.st.com


▲Up To Search▲   

 
Price & Availability of AN969

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X